package com.heima.kafka.listener;

import org.apache.kafka.clients.consumer.Consumer;
import org.apache.kafka.clients.consumer.ConsumerRecord;
import org.springframework.stereotype.Component;
import org.springframework.util.StringUtils;

@Component
public class KafkaListener {

    /*@org.springframework.kafka.annotation.KafkaListener(topics = "heima")
    public void onMsg(String msg){
        System.out.println(msg);
    }*/

    @org.springframework.kafka.annotation.KafkaListener(topics = "heima")
    public void onMsg(ConsumerRecord<String, String> record, Consumer<String,String> consumer){
        if(!StringUtils.isEmpty(record.value())){
            System.out.println(record.value());

            consumer.commitAsync();
        }
    }
}
